package com.jy.adscm.operation.mscyb.controller;


import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.mscyb.bean.JqbzSettings;
import com.jy.adscm.operation.mscyb.bean.JqzzSettingParts;
import com.jy.adscm.operation.mscyb.service.JqzzSettingPartsService;
import com.jy.adscm.operation.purchase.bean.Purchasebom;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-05-21
 */
@RestController
@RequestMapping("/adscm/operation/jqzz/jqzzSettingParts")
public class JqzzSettingPartsController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    JqzzSettingPartsService jqzzSettingPartsInputService;

    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody JqzzSettingParts jqzzSettingParts, HttpServletRequest request){
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        boolean insert = jqzzSettingPartsInputService.insert(jqzzSettingParts);
        return  new SimpleCoreResponse("200","新增成功",insert);
    }
    @RequestMapping("delete/{id}")
    public SimpleCoreResponse delete(@PathVariable Integer id, HttpServletRequest request){
        boolean result = jqzzSettingPartsInputService.deleteById(id);
        return  new SimpleCoreResponse("200","删除成功",result);
    }

    @RequestMapping("selectByPid/{pid}")
    public  SimpleCoreResponse  selectBybid(@PathVariable String pid) throws AdscmSystemException {
        List<JqzzSettingParts> jqzzSettingPartsInputs = jqzzSettingPartsInputService.selectJqzzSettingPartsByPid(pid);
        return  new SimpleCoreResponse("200","查询成功",jqzzSettingPartsInputs);
    }
    @RequestMapping("selectAll/{id}")
    public  SimpleCoreResponse  selectAll(@PathVariable Integer id) throws  AdscmSystemException{
        List<JqbzSettings>   JqbzSettings = jqzzSettingPartsInputService.selectAll(id);
        return  new SimpleCoreResponse("200","查询成功",JqbzSettings);
    }
}

